<script>
export default {
	onLaunch: function() {
		console.log('onLaunch');
		// 获取当前手机系统信息
		const system = this.getSystemInfo();
		this.$store.dispatch('saveSysinfoToVuex', system);
		// 判断是否进入引导页
		this.goHomeOrGoGuide();
	},
	onShow: function() {
	
		console.log('App Show');
		// 进入广告页
		this.goAdvPage();
	},
	onHide: function() {
		console.log('App Hide');
		// hide的时候存储当前时间
		uni.setStorageSync('advTimes', new Date());
	},
	methods: {
		goAdvPage() {
			const nowTimes = new Date();
			const storageTimes = uni.getStorageSync('advTimes');
			const oldTimes = new Date(storageTimes);

			if (nowTimes - oldTimes > 30 * 60 * 60 * 1000) {
				uni.reLaunch({
					url: '/pages/adv/adv'
				});
			}
		},
		goHomeOrGoGuide() {
			if (this.checkGuide()) {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			} else {
				uni.reLaunch({
					url: '/pages/guide/guide'
				});
			}
		},
		getSystemInfo() {
			return uni.getSystemInfoSync();
		},
		checkGuide() {
			return uni.getStorageSync('guide') || false;
		}
	}
};
</script>
<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import 'uview-ui/index.scss';
</style>
